// 云函数入口文件
const cloud = require('wx-server-sdk')
const got = require('got')
var appid = 'wxd96003e45a834be9';
var appsecret = 'a901ba8d7a71392caa2b06aa65a283ba';
var url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid + '&secret=' + appsecret;

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const token_response = await got.get(url)

  let token = JSON.parse(token_response.body).access_token;
  
  let fStream = await got('https://api.weixin.qq.com/wxa/getwxacode?access_token=' + token,{
    method:'POST',
    headers:{
      'Content-Type':'application/json'
    },
    body:JSON.stringify({
      'path':'pages/two-fileSave-27photo/two-fileSave-27photo'
    })
  })

  return await cloud.uploadFile({
    cloudPath:'qrcode.jpg',
    fileContent:fStream.body,
  })

}